package com.example.cash_register.model.product;

import com.example.cash_register.controller.ErrRedirectException;
import com.example.cash_register.model.AbsValidator;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;

@Slf4j
@Component
public class PriceValidator extends AbsValidator {
    public String validate(String module,String redirectUrl,String name) {
        name = super.validate(module,redirectUrl,name);
        try {
            double number = Double.parseDouble(name);

            if(number <= 0) {
                throw new ErrRedirectException("value 必须大于0", module, redirectUrl);
            }
        }catch (NumberFormatException e) {
            throw new ErrRedirectException("value 必须是数字",module,redirectUrl);
        }
        return name;
    }
}
